//
//  MKScanQrcodeResultHandler.m
//  Teleport
//
//  Created by RLY on 2020/6/2.
//  Copyright © 2020 xxt. All rights reserved.
//

#import "TJQrcodeResultHandler.h"
#import "TJTransferController.h"

@implementation TJQrcodeResultHandler
//可以跳转
+ (void)QrCodeResultHandlerWithController:(UIViewController *)controller result:(NSString *)result {
    [self QrCodeResultHandlerWithController:controller result:result isNeedHandle:YES complete:nil];
}

// isNeedHandle 是否跳转
+ (void)QrCodeResultHandlerWithController:(UIViewController *)controller result:(NSString *)result isNeedHandle:(BOOL)isNeedHandle complete:(nullable void (^)(NSDictionary *dict))complete {
    
       
       if (![result containsString:QRCodePrefix]) {
           [controller alertWithTitle:@"提示".localizedString message:@"不能识别的二维码".localizedString leftButtonName:@"确定".localizedString rightButtonName:nil leftButtonBlock:nil rightButtonBlock:nil];
           return;
       }
       
       result = [result stringByReplacingOccurrencesOfString:QRCodePrefix withString:@""];
       //json字符串转字典
       NSDictionary *resultDict = [Tools convertToDict:result];
    
    //是否跳转
    if(isNeedHandle == NO) {
       if (complete)  complete(resultDict);
        return;
    }
    
       if ([resultDict[@"type"] isEqualToString:@"transfer"]) {//钱包转账提出界面
           TJTransferController *transferController = [[TJTransferController alloc] init];
           transferController.UID = resultDict[@"uuid"];
           [controller.navigationController pushViewController:transferController animated:YES];
            return;
        }
    
}



@end
